home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / Logger.lha / logger1.0 / CLogger < prev    next >
Encoding:
Text File  |  1995-04-19  |  4.9 KB  |  147 lines

  1. /**************************************************  $VER: CLogger v1.0 (19/04/95)
  2. * Andy's newest Arexx project.                    *
  3. * This latest project reads from a configuration  *
  4. * file which lists all your log files and trims   *
  5. * them to a specified length.                     *
  6. * This is a variation on my Logger script, that   *
  7. * does the trimming usin Arexx, as opposed to an  *
  8. * external command, 'Tail', that the Logger script*
  9. * used. Obviously because of this it is a fair bit*
  10. * bit slower than Logger, but this is all my own  *
  11. * work.                                           *
  12. * Well almost, it does require the incredible     *
  13. * RexxReqTools by Rafael D'Halleweyn.             *
  14. **************************************************/
  15.  
  16.  
  17. /* variables you may change                      */
  18. configfile = 's:logger.config'
  19. tempfile = 't:logger.temp'
  20. lf         = '0a'x
  21.  
  22.  
  23.  
  24.  
  25. /* check for rexxreqtools                        */
  26. if exists('LIBS:rexxreqtools.library') then do
  27.     call addlib('rexxreqtools.library',0,-30)
  28. end
  29.  
  30. parse arg arguments
  31. if compress(arguments) ~= '' then do
  32.     if find(Upper(arguments),'LOGRESET') > 0 then signal logreset
  33.     if find(Upper(arguments),'CONFIG') > 0 then conf = 1
  34.     if find(Upper(arguments),'FORCE') > 0 then force = 1
  35.     if conf ~= 1&force ~= 1 then signal usage
  36. end
  37.  
  38. /* first get the config file                     */
  39.  
  40. if ~exists(configfile)|conf = 1 then do
  41.         call rtezrequest('    Are you sure you would'lf'like to create a new config file?','_Yes |_No','CLogger v1.0','rt_reqpos = reqpos_centerscr')
  42.         frt = rtresult
  43.         if frt = 0&conf = 1 then do
  44.             call rtezrequest('Do you wish to use the old config?','_Yes|_No','CLogger v1.0','rt_reqpos=reqpos_centerscr')
  45.             srt = rtresult
  46.             if srt = 0 then Exit
  47.             if srt = 1 then signal main
  48.         end
  49.         if frt = 0&conf ~= 1 then Exit
  50.     call loggerconfig
  51. end
  52.  
  53.  
  54.  
  55.  
  56. main:
  57. /* read the config file and 'tail' each log      */
  58.  
  59. call open(InpFile,configfile,R)
  60.  
  61. do forever
  62.     line = readln(InpFile)
  63.     if EOF(InpFile) then break
  64.     if left(line,1) ~= "#" then do
  65.         if compress(line) ~= ""  then do
  66.             taillen = subword(line,2,1)
  67.             tailfile = subword(line,1,1)
  68.             if exists(tailfile) then do
  69.                 if force ~= 1 then do
  70.                     call rtezrequest(' Are you sure you wish to trim'lf tailfile lf' to last 'taillen,'_Yes | _No','CLogger v1.0','rt_reqpos=reqpos_centerscr')
  71.                     frt = rtresult
  72.                     end
  73.                 if frt ~= 0|force = 1 then do
  74.                     call open(Tailer,tailfile,R)
  75.                     counter = 0
  76.                     do forever
  77.                         call readln(Tailer)
  78.                         if EOF(Tailer) then break
  79.                         counter = counter + 1
  80.                     end
  81.                     call close(tailer)
  82.                     call open(tailer,tailfile,R)
  83.                     call open(finfile,tempfile,W)
  84.                     if taillen >= counter then break
  85.                     clip = counter - taillen
  86.                     ncon = 0
  87.                     do forever
  88.                         line = readln(tailer)
  89.                         if EOF(tailer) then break
  90.                         if ncon >= clip then do
  91.                             writeln(finfile,line)
  92.                         end
  93.                         ncon = ncon + 1
  94.                     end
  95.                     call close(tailer)
  96.                     call close(finfile)
  97.                     address command 'delete >NIL: 'tailfile'.bak'
  98.                     address command 'rename 'tailfile tailfile'.bak'
  99.                     address command 'copy t:logger.temp 'tailfile' QUIET'
  100.                     address command 'delete >NIL: t:logger.temp'
  101.                 end
  102.             end
  103.         end
  104.     end
  105. end
  106.  
  107. call close(InpFile)
  108.  
  109. exit
  110. usage:
  111.  
  112. say 'Logger [CONFIG] [FORCE] [LOGRESET]'
  113. exit
  114.  
  115.  
  116. loggerconfig:
  117. call open(Outfile,configfile,W)
  118. call writeln(OutFile,'# Config file created by Logger v1.0')
  119. do forever
  120.     logstring = rtfilerequest('work:',,'Logger.config',,'rtfi_matchpat=#?.log rtfi_flags=freqf_patgad rt_reqpos=reqpos_centerscr')
  121.     frt = rtresult
  122.     if frt = 0 then break
  123.     logno = rtgetlong('200','trim 'logstring' to how many?','Logger.config',,'rtgl_min=0 rt_reqpos=reqpos_centerscr')
  124.     frt = rtresult
  125.     if frt = 0 then break
  126.     call writeln(Outfile,logstring' 'logno)
  127. end
  128. call close(outfile)
  129. return
  130.  
  131.  
  132. /*logresetter*/
  133. logreset:
  134. rtezrequest('Are you sure you wish to reset your logs?'lf'This will replace all the logfiles in your config'lf'with their backups!','_Yes|_No','Logger v1.0','rt_reqpos=reqpos_centerscr rtez_defaultresponse=0')
  135. open(inpfile,configfile,R)
  136. do forever
  137.     line = readln(inpfile)
  138.     if EOF(InpFile) then break
  139.     rfile = subword(line,1,1)
  140.     if exists(rfile'.bak') then do
  141.         address command 'delete >NIL: 'rfile
  142.         address command 'rename 'rfile'.bak' rfile
  143.     end
  144. end
  145. exit
  146.  
  147.